package com.neusoft.elmboot.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.elmboot.po.User;

@Mapper
public interface UserMapper {

	@Select("select * from user where userId=#{userId} and password=#{password}")
	public User getUserByIdByPass(User user);
	
	@Select("select count(*) from user where userId=#{userId} and password<>'0'")
	public int getUserById(String userId);
	
	@Update("update user set password=#{password},userName=#{userName},userSex=#{userSex},userImg=#{userImg} where userId=#{userId}")
	public int saveUser(User user);
	
	//往数据库存储私钥，返回标志
	@Insert("insert into user values(#{userId},'0','0','0','0',1,#{privateKey},#{publicKey})")
	public int saveKey(User user);
	
	//从数据库取私钥，返回私钥
	@Select("select privateKey from user where userId=#{userId}")
	public String  getPrivateKey(String userId);

		
	//从数据库取公钥，返回公钥
	@Select("select publicKey from user where userId=#{userId}")
	public String  getPublicKey(String userId);
	
	@Select("select * from user where userId=#{userId}")
	public User getEntireUserById(String userId);

	public int updateUser(User user);
	
	@Update("update user set token=#{token} where userId=#{userId}")
	public int updateToken(User user);
}
